/*
 * Copyright (C) Francisco Morero Peyrona. All rights reserved.
 *
 * This software is published under the terms of Open Source
 * License version 1.1, a copy of which has been included with this
 * distribution in the License.txt file.
 */

package jdbcmanager.tree;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import jdbcmanager.app.*;
import jdbcmanager.swing.*;

/**
 * Just this: the toolbar associated with the DBMS tree.
 *
 * @author Francisco Morero Peyrona
 */
public final class TreeToolBar extends JxToolBar
{
   private JActionSet actions;
   private JButton    btnDeskTool;

   /**
    * Class constructor
    * @param as
    */
   public TreeToolBar( JActionSet as )
   {
      this.actions = as;
      init();
   }
   
   public void setEnabled( boolean b )
   {
      Action[] act = this.actions.getActions();
      
      super.setEnabled( b );
      
      for( int n = 0; n < act.length; n++ )
          act[n].setEnabled( false );
   }

   /**
    * Disable all tool-bar buttons except Desktop button (the last one)
    */
   public void disableAllExceptDesktop()
   {
      setEnabled( false );
      this.btnDeskTool.setEnabled( true );
   }

   //-------------------------------------------------------------------------//

   /**
    * GUI initialization
    */
   private void init()
   {
      add( this.actions );
      addSeparator( new Dimension( 32,16 ) );

      // Add Desk-Tools button (this btn exists in the ToolBar, but no in the PopupMenu)
      this.btnDeskTool = add( new ImageIcon( getClass().getResource( "images/tb_desktool.gif" ) ), "Desktop related tools" );

      // When this.btnDeskTool is clicked, the popup shows up
      this.btnDeskTool.addActionListener( new ActionListener()
      {
         public void actionPerformed( ActionEvent evt )
         {
            App.getFrameMain().showDesktopPopup( btnDeskTool, 0, btnDeskTool.getHeight() );
         }
      } );
   }
}